package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Setmeal;
import com.itheima.reggie.entity.SetmealDto;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetMealMapper {
    @Select("SELECT COUNT(*) FROM setmeal WHERE category_id=#{categoryId}")
    Long findSetMealByCategory(Long id);

    @Insert("INSERT INTO setmeal VALUES (null,#{categoryId},#{name},#{price},#{status},#{code},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void save(SetmealDto setmealDto);

    List<Setmeal> findByName(@Param("name") String name);

    Long queryDishWithStatus(@Param("ids") List<Long> ids);

    void deleteByIds(@Param("ids") List<Long> ids);

    @Select("SELECT * FROM setmeal WHERE category_id=#{categoryId} AND status = #{status}")
    List<Setmeal> list(Long categoryId, Integer status);

    @Select("SELECT * FROM setmeal WHERE id = #{id}")
    Setmeal findById(Long id);

    void setStatus(@Param("status") Integer status, @Param("ids") List<Long> ids);

    void update(@Param("setmealDto") SetmealDto setmealDto);
}
